<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Question_model extends CI_Model
{
	
	public function __construct()
	{
		parent::__construct();		
	}
	
	function get_question_by_client_id($id){
		$this->db->select('projects.id as pId,projects.name as pName,tasks.*,task_notes.*');
		$this->db->from('projects');
		$this->db->where('projects.client_id',$id);
		$this->db->join('tasks','tasks.project_id = projects.id');
		$this->db->join('task_notes','task_notes.task_id = tasks.id AND task_notes.note_type = 2');				
		$this->db->order_by('task_notes.date','DESC');
		return $this->db->get()->result();		
	}
	
	public function answered($qid){		
		if(is_array($qid)){
			foreach($qid as $qID){
			$this->db->update('task_notes',array('is_answered'=>1),array('id' => $qID));		
			}			
		}else {
		$this->db->update('task_notes',array('is_answered'=>1),array('id' => $qid));	
		}		
	}
	
	public function unanswered($qid){	
		if(is_array($qid)){
			foreach($qid as $qID){
			$this->db->update('task_notes',array('is_answered'=>0),array('id' => $qID));		
			}			
		}else {
		$this->db->update('task_notes',array('is_answered'=>0),array('id' => $qid));	
		}
	}
	
	//public function answered_ajax()
	
	
}